package com.zy.qudadid.ui.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.MyLocationStyle;
import com.amap.api.maps2d.overlay.DrivingRouteOverlay;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkRouteResult;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.pingplusplus.android.Pingpp;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zy.bean.Dingdan;
import com.zy.bean.PositionEntity;
import com.zy.gaode.OnLocationGetListener;
import com.zy.gaode.RegeocodeTask;
import com.zy.gaode.RouteTask;
import com.zy.lcpassenger.R;
import com.zy.qudadid.model.DownWindStroke;
import com.zy.qudadid.model.ReportTitle;
import com.zy.qudadid.model.StrokeInfor;
import com.zy.qudadid.model.User;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.presenter.MainPresenter;
import com.zy.qudadid.ui.activity.base.ToolBarActivity;
import com.zy.qudadid.ui.adapter.ReportTitleAdapter;
import com.zy.qudadid.ui.view.MainView;
import com.zy.qudadid.ui.widget.BoardingDialog;
import com.zy.qudadid.ui.widget.CallCarDialogNoWaitting;
import com.zy.qudadid.ui.widget.CancelCallCarDialog;
import com.zy.qudadid.ui.widget.CustomImageView;
import com.zy.qudadid.ui.widget.IsGetOrderDialog;
import com.zy.qudadid.ui.widget.ListViewDialog;
import com.zy.qudadid.ui.widget.OneButtonImgDialog;
import com.zy.qudadid.ui.widget.OneButtonReportDialog;
import com.zy.qudadid.ui.widget.PayDetailDialog;
import com.zy.qudadid.ui.widget.PayDialog;
import com.zy.qudadid.ui.widget.SelectPayDialog;
import com.zy.qudadid.ui.widget.TwoButtonDialog;
import com.zy.qudadid.utils.AESCrypt;
import com.zy.qudadid.utils.AMapUtil;
import com.zy.qudadid.utils.ActivityUtil;
import com.zy.qudadid.utils.Bun;
import com.zy.qudadid.utils.StringUtil;
import com.zy.qudadid.utils.ToolsUtil;
import com.zy.qudadid.utils.UserUtil;
import com.zy.util.JsonUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;
import cn.qqtheme.framework.picker.LinkagePicker;
import cn.qqtheme.framework.picker.NumberPicker;
import cn.qqtheme.framework.picker.OptionPicker;
import cn.qqtheme.framework.util.DateUtils;
import okhttp3.Call;

//import com.zhy.http.okhttp.OkHttpUtils;
//import com.zhy.http.okhttp.callback.StringCallback;



/**
 * Created by ASUS on 2017/2/16.
 */

public class MainActivity extends ToolBarActivity<MainPresenter> implements MainView, LocationSource, AMapLocationListener, View.OnClickListener, OnLocationGetListener, AMap.OnCameraChangeListener {

    public static int flag_carType = 0;//出租车:0 顺风车：1 网约车：2
    public int realtimeOradvance = 1;//出租车_实时约车：1 出租车_预约约车：2    网约车_实时约车：5 网约车_预约约车：6
    public int inOrthrough = 1;//市内行程：1 跨城行程：2
    public int ordinaryOrspecial = 0;//普通车：0 专车：1
    public int spellCar = 1;//是否拼车，1不拼车现在出发；2不平车预约时间出发；3拼车
    public static int rentState = 0;//出租车状态  未叫车：0    司机已接单，待上车：1     行驶中：2     行驶完成，待支付：3

    private View bottom_layout;
    private View bottom_layout_downwind;
    @Bind(R.id.tv_title)
    TextView tv_title;
    @Bind(R.id.img_show)
    ImageView img_show;
    @Bind(R.id.ll_place)
    LinearLayout ll_place;
    @Bind(R.id.location_bt)
    ImageView location_bt;
    /*bottom_layout*/
    @Bind(R.id.tv_rent_car)
    TextView tv_rent_car;
    @Bind(R.id.tv_downwind_car)
    TextView tv_downwind_car;
    @Bind(R.id.tv_net_car)
    TextView tv_net_car;
    @Bind(R.id.ll_rent_car)
    LinearLayout ll_rent_car;
    @Bind(R.id.ll_downwind_car)
    LinearLayout ll_downwind_car;
    @Bind(R.id.ll_net_car)
    LinearLayout ll_net_car;
    @Bind(R.id.ll_callcar)
    LinearLayout ll_callcar;
    /*实时约车、预约约车*/
    // 出租车
    @Bind(R.id.ll_realtime)
    LinearLayout ll_realtime;
    @Bind(R.id.ll_advance)
    LinearLayout ll_advance;
    @Bind(R.id.ll_people)
    LinearLayout ll_people;
    @Bind(R.id.tv_people)
    TextView tv_people;
    @Bind(R.id.img_realtime)
    ImageView img_realtime;
    @Bind(R.id.tv_realtime)
    TextView tv_realtime;
    @Bind(R.id.img_advance)
    ImageView img_advance;
    @Bind(R.id.tv_advance)
    TextView tv_advance;
    @Bind(R.id.tv_time_realtime_number)
    TextView tv_time_realtime_number;
    @Bind(R.id.tv_time_realtime_min)
    TextView tv_time_realtime_min;
    @Bind(R.id.tv_time_advance)
    TextView tv_time_advance;
    @Bind(R.id.ll_time)
    LinearLayout ll_time;
    @Bind(R.id.tv_timetype)
    TextView tv_timetype;
    @Bind(R.id.ll_time_choosed)
    LinearLayout ll_time_choosed;
    @Bind(R.id.ll_time_nochoose)
    LinearLayout ll_time_nochoose;
    @Bind(R.id.tv_money)
    TextView tv_money;

    // 网约车
    @Bind(R.id.ll_3time)
    LinearLayout ll_3time;
    @Bind(R.id.tv_3timetype)
    TextView tv_3timetype;
    @Bind(R.id.ll_3time_choosed)
    LinearLayout ll_3time_choosed;
    @Bind(R.id.ll_3time_nochoose)
    LinearLayout ll_3time_nochoose;
    @Bind(R.id.tv_3time_realtime_number)
    TextView tv_3time_realtime_number;
    @Bind(R.id.tv_3time_realtime_min)
    TextView tv_3time_realtime_min;
    @Bind(R.id.tv_3time_advance)
    TextView tv_3time_advance;
    @Bind(R.id.ll_3callcar)
    LinearLayout ll_3callcar;
    /*实时约车、预约约车*/
    @Bind(R.id.ll_3realtime)
    LinearLayout ll_3realtime;
    @Bind(R.id.ll_3advance)
    LinearLayout ll_3advance;
    @Bind(R.id.ll_3people)
    LinearLayout ll_3people;
    @Bind(R.id.tv_3people)
    TextView tv_3people;
    @Bind(R.id.img_3realtime)
    ImageView img_3realtime;
    @Bind(R.id.tv_3realtime)
    TextView tv_3realtime;
    @Bind(R.id.img_3advance)
    ImageView img_3advance;
    @Bind(R.id.tv_3advance)
    TextView tv_3advance;
    @Bind(R.id.tv_3money)
    TextView tv_3money;

    // 顺风车
    @Bind(R.id.tv2Time)
    TextView tv2Time;
    @Bind(R.id.tv2TimeDay)
    TextView tv2TimeDay;
    @Bind(R.id.tv2People)
    TextView tv2People;
    @Bind(R.id.tv2Price)
    TextView tv2Price;
    @Bind(R.id.ll2Release)
    LinearLayout ll2Release;
    @Bind(R.id.ll2Time)
    LinearLayout ll2Time;
    @Bind(R.id.ll2People)
    LinearLayout ll2People;
    @Bind(R.id.tv_downwind_finish_count)
    TextView tv_downwind_finish_count;
    @Bind(R.id.tv_downwind_have_count)
    TextView tv_downwind_have_count;
    @Bind(R.id.tv_finish_time)
    TextView tv_finish_time;
    @Bind(R.id.tv_have_time)
    TextView tv_have_time;
    @Bind(R.id.tv_finish_place)
    TextView tv_finish_place;
    @Bind(R.id.tv_have_place)
    TextView tv_have_place;

    /*上部上车下车地点*/
    @Bind(R.id.ll_shangche)
    LinearLayout ll_shangche;
    @Bind(R.id.ll_qunaer)
    LinearLayout ll_qunaer;
    @Bind(R.id.tv_shangche)
    TextView tv_shangche;
    @Bind(R.id.tv_qunaer)
    TextView tv_qunaer;
    @Bind(R.id.txtNearCarNum)
    TextView txtNearCarNum;

    /*司机已接单*/
    @Bind(R.id.tv_driver_name)
    TextView tv_driver_name;
    @Bind(R.id.tv_driver_carnumber)
    TextView tv_driver_carnumber;
    @Bind(R.id.ll_cancel)
    LinearLayout ll_cancel;

    /*我已上车*/
    @Bind(R.id.ll_isgetorde_top)
    LinearLayout ll_isgetorde_top;
    @Bind(R.id.ll_isgetorder_bottom)
    LinearLayout ll_isgetorder_bottom;
    @Bind(R.id.ll_oncar)
    LinearLayout ll_oncar;
    BoardingDialog boardingDialog;

    @Bind(R.id.tv_money2)
    TextView tv_money2;
    @Bind(R.id.tv_getInCar)
    TextView tv_getInCar;
    @Bind(R.id.tv_Driving)
    TextView tv_Driving;
    @Bind(R.id.img_driver2)
    ImageView img_driver2;
    @Bind(R.id.ll_call)
    LinearLayout ll_call;
    @Bind(R.id.tv_startPlace)
    TextView tv_startPlace;
    @Bind(R.id.tv_stopPlace)
    TextView tv_stopPlace;
    @Bind(R.id.tv_driveringContent1)
    TextView tv_driveringContent1;
    @Bind(R.id.tv_driveringContent2)
    TextView tv_driveringContent2;

    /*我已下车并支付*/
    @Bind(R.id.ll_pay_bottom)
    LinearLayout ll_pay_bottom;
    @Bind(R.id.ll_pay)
    LinearLayout ll_pay;
    @Bind(R.id.rlSelectPay)
    RelativeLayout rlSelectPay;
    @Bind(R.id.img_pay_type)
    ImageView img_pay_type;
    @Bind(R.id.tv_pay_type)
    TextView tv_pay_type;

    /*顺风车*/
//    @Bind(R.id.ll_release)
//    LinearLayout ll_release;
    @Bind(R.id.ll_in_city)
    LinearLayout ll_in_city;
    @Bind(R.id.ll_through_city)
    LinearLayout ll_through_city;
    @Bind(R.id.img_in_city)
    ImageView img_in_city;
    @Bind(R.id.tv_in_city)
    TextView tv_in_city;
    @Bind(R.id.img_through_city)
    ImageView img_through_city;
    @Bind(R.id.tv_through_city)
    TextView tv_through_city;
    @Bind(R.id.rl_stroke)
    RelativeLayout rl_stroke;
    @Bind(R.id.rl_stroke_commonly)
    RelativeLayout rl_stroke_commonly;
    @Bind(R.id.ll_stroke_detail)
    LinearLayout ll_stroke_detail;
    @Bind(R.id.ll_stroke_commonly_detail)
    LinearLayout ll_stroke_commonly_detail;

    /*网约车*/
    @Bind(R.id.img_ordinary_car)
    ImageView img_ordinary_car;
    @Bind(R.id.ll_ordinary_car)
    LinearLayout ll_ordinary_car;
    @Bind(R.id.img_special_car)
    ImageView img_special_car;
    @Bind(R.id.ll_special_car)
    LinearLayout ll_special_car;
    @Bind(R.id.rlTag)
    RelativeLayout rlTag;

//    @Bind(R.id.rl_menu_stroke)
//    RelativeLayout rl_menu_stroke;

    SlidingMenu menu;


    /*显示地图*/
    @Bind(R.id.map)
    MapView mMapView;
    AMap aMap;

    /*显示定位蓝点*/
    OnLocationChangedListener mListener;
    AMapLocationClient mlocationClient;
    AMapLocationClientOption mLocationOption;

    public static double lat, lng;//当前经纬度
    public static String place;//当前地点
    public static String city;//当前城市

    public static String shangche = "";//上车地点
    public static String shangchelat = "";
    public static String shangchelng = "";

    public static String quna = "";//目的地
    public static String qunalat = "";
    public static String qunalng = "";

    String shangchedidian;

    /*驾车出行路线规划*/
    private RouteSearch routeSearch;
    private LatLonPoint youLatLonPoint;
    private LatLonPoint myLatLonPoint;
    private DrivingRouteOverlay drivingRouteOverlay;//用于清除其他路线
    private DriveRouteResult driveRouteResults;// 驾车模式查询结果
    String mile = "";//距离(米)
    float milefloat = 0;//距离(米)
    String des = "";//预计时间

    private UiSettings mUiSettings;

    private boolean isShow = true;

    TextView tv_username;
    TextView tv_phone;
    CustomImageView img_title;

    CancelCallCarDialog cancelCallCarDialog;

    private RegeocodeTask mRegeocodeTask;//声明逆地理编码对象

    @Override
    protected CharSequence provideTitle() {
        return "定位城市";
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.ui_activity_main;
    }

    @Override
    public void initListeners() {

    }

    @Override
    public MainPresenter createPresenter() {
        return new MainPresenter();
    }


    @OnClick({R.id.tv_rent_car, R.id.tv_downwind_car, R.id.tv_net_car})
    public void bottom_OnClick(View view) {
        ll_rent_car.setVisibility(View.GONE);
        ll_downwind_car.setVisibility(View.GONE);
        ll_net_car.setVisibility(View.GONE);
        tv_rent_car.setTextColor(ContextCompat.getColor(this, R.color.txt_gray));
        tv_downwind_car.setTextColor(ContextCompat.getColor(this, R.color.txt_gray));
        tv_net_car.setTextColor(ContextCompat.getColor(this, R.color.txt_gray));
        tv_rent_car.setBackgroundResource(R.drawable.weixuanzhong);
        tv_downwind_car.setBackgroundResource(R.drawable.weixuanzhong);
        tv_net_car.setBackgroundResource(R.drawable.weixuanzhong);
        switch (view.getId()) {
            case R.id.tv_rent_car://出租车
                spellCar = 1;
                realtimeOradvance = 1;
                ll_rent_car.setVisibility(View.VISIBLE);
                tv_rent_car.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                tv_rent_car.setBackgroundResource(R.drawable.xuanzhong);
                flag_carType = 0;
                break;
            case R.id.tv_downwind_car://顺风车
                ll_downwind_car.setVisibility(View.VISIBLE);
                tv_downwind_car.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                tv_downwind_car.setBackgroundResource(R.drawable.xuanzhong);
                flag_carType = 1;
                spellCar = 3;
                break;
            case R.id.tv_net_car://网约车
                spellCar = 5;
                realtimeOradvance = 5;
                ll_net_car.setVisibility(View.VISIBLE);
                tv_net_car.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                tv_net_car.setBackgroundResource(R.drawable.xuanzhong);
                flag_carType = 2;
                break;
        }
    }

    @OnClick({R.id.ll_realtime,R.id.ll_3realtime ,R.id.ll_advance,R.id.ll_3advance,R.id.ll_people,R.id.ll_3people, R.id.ll_time,R.id.ll_3time, R.id.img_show, R.id.location_bt, R.id.ll_callcar, R.id.ll_3callcar,R.id.ll_oncar, R.id.ll_pay, R.id.ll_cancel})
    public void realtimeOradvance_OnClick(View view) {
        switch (view.getId()) {
            case R.id.ll_realtime://出租车实时约车
                realtimeOradvance = 1;
                img_realtime.setBackgroundResource(R.drawable.shishi);
                tv_realtime.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_realtime.setBackgroundResource(R.drawable.shape_3);
                img_advance.setBackgroundResource(R.drawable.yuyue_hui);
                tv_advance.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_advance.setBackgroundResource(R.drawable.shape_6);
                tv_timetype.setText("预计时间");
//                ll_time_choosed.setVisibility(View.VISIBLE);
//                ll_time_nochoose.setVisibility(View.GONE);
                if (des.equals("")) {
                    ll_time_choosed.setVisibility(View.GONE);
                    ll_time_nochoose.setVisibility(View.VISIBLE);
                } else {
                    ll_time_choosed.setVisibility(View.VISIBLE);
                    ll_time_nochoose.setVisibility(View.GONE);
                }
                tv_time_realtime_number.setVisibility(View.VISIBLE);
                tv_time_realtime_min.setVisibility(View.GONE);
                tv_time_advance.setVisibility(View.GONE);
                spellCar = 1;
                break;
            case R.id.ll_advance://出租车预约约车
                realtimeOradvance = 2;
                img_realtime.setBackgroundResource(R.drawable.shishi_hui);
                tv_realtime.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_realtime.setBackgroundResource(R.drawable.shape_6);
                img_advance.setBackgroundResource(R.drawable.yuyue);
                tv_advance.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_advance.setBackgroundResource(R.drawable.shape_3);
                tv_timetype.setText("选择时间");
                ll_time_choosed.setVisibility(View.GONE);
                ll_time_nochoose.setVisibility(View.VISIBLE);
                spellCar = 2;
                break;
            case R.id.ll_3realtime://网约车实时约车
                realtimeOradvance = 5;
                img_3realtime.setBackgroundResource(R.drawable.shishi);
                tv_3realtime.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_3realtime.setBackgroundResource(R.drawable.shape_3);
                img_3advance.setBackgroundResource(R.drawable.yuyue_hui);
                tv_3advance.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_3advance.setBackgroundResource(R.drawable.shape_6);
                tv_3timetype.setText("预计时间");
//                ll_time_choosed.setVisibility(View.VISIBLE);
//                ll_time_nochoose.setVisibility(View.GONE);
                if (des.equals("")) {
                    ll_3time_choosed.setVisibility(View.GONE);
                    ll_3time_nochoose.setVisibility(View.VISIBLE);
                } else {
                    ll_3time_choosed.setVisibility(View.VISIBLE);
                    ll_3time_nochoose.setVisibility(View.GONE);
                }
                tv_3time_realtime_number.setVisibility(View.VISIBLE);
                tv_3time_realtime_min.setVisibility(View.GONE);
                tv_3time_advance.setVisibility(View.GONE);
                if(ordinaryOrspecial == 0) {
                    spellCar = 5;
                }else{
                    spellCar = 7;
                }
                break;
            case R.id.ll_3advance://网约车预约约车
                realtimeOradvance = 6;
                img_3realtime.setBackgroundResource(R.drawable.shishi_hui);
                tv_3realtime.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_3realtime.setBackgroundResource(R.drawable.shape_6);
                img_3advance.setBackgroundResource(R.drawable.yuyue);
                tv_3advance.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_3advance.setBackgroundResource(R.drawable.shape_3);
                tv_3timetype.setText("选择时间");
                ll_3time_choosed.setVisibility(View.GONE);
                ll_3time_nochoose.setVisibility(View.VISIBLE);
                if(ordinaryOrspecial == 0) {
                    spellCar = 6;
                }else{
                    spellCar = 8;
                }
                break;
            case R.id.ll_time://出租车_预约约车_选择时间
                if (realtimeOradvance == 2) {
                    onLinkagePicker();
                }
                break;
            case R.id.ll_3time://网约车_预约约车_选择时间
                if (realtimeOradvance == 6) {
                    onLinkagePicker();
                }
                break;
            case R.id.ll_people:
                final NumberPicker picker = new NumberPicker(this);
                picker.setRange(1, 4,"4");//数字范围
                picker.setSelectedItem(1);
//                picker.setLabel("人");
                picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
                    @Override
                    public void onOptionPicked(String option) {
//                        if(option.equals("4人")) {
//                            people = "4";
//                            tv_people.setText(option);
//                        }else{
                        people = option;
                        tv_people.setText(option);
//                        }

//                        if (canpeople)
//                            getMoney();
                    }
                });
                picker.show();
                break;
            case R.id.ll_3people:
                final NumberPicker picker3 = new NumberPicker(this);
                picker3.setRange(1, 4,"4");//数字范围
                picker3.setSelectedItem(1);
//                picker.setLabel("人");
                picker3.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
                    @Override
                    public void onOptionPicked(String option) {
//                        if(option.equals("4人（包车）")) {
//                            people3 = "4";
//                            tv_3people.setText(option);
//                        }else{
                        people3 = option;
                        tv_3people.setText(option);
//                        }

//                        if (canpeople)
//                            getMoney();
                    }
                });
                picker3.show();
                break;
            case R.id.img_show://底部layout显示隐藏
                if (isShow) {
                    bottom_layout.setVisibility(View.GONE);
                    isShow = false;
                    img_show.setImageResource(R.drawable.upload);
                } else {
                    bottom_layout.setVisibility(View.VISIBLE);
                    isShow = true;
                    img_show.setImageResource(R.drawable.download);
                }
                break;
            case R.id.location_bt://底部layout显示隐藏
                LatLng latLng = new LatLng(lat, lng);
                //aMap.moveCamera(CameraUpdateFactory.zoomTo(19));
                aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));//然后可以移动到定位点,使用animateCamera就有动画效果
                break;
            case R.id.ll_callcar://出租车确认叫车

                Map map1 = new HashMap();
                map1.put("user_id", new UserUtil(getContext()).getUserId());
                map1.put("car_type", spellCar);
                map1.put("chufadi", MainActivity.shangche);
                map1.put("chufadijingdu", MainActivity.shangchelng);
                map1.put("chufadiweidu", MainActivity.shangchelat);
                map1.put("mudidi", MainActivity.quna);
                map1.put("mudijingdu", MainActivity.qunalng);
                map1.put("mudiweidu", MainActivity.qunalat);
                map1.put("shouji", new UserUtil(getContext()).getUser().mobile);
                map1.put("people", people);
                if (spellCar == 1) {//出租车实时约车

                } else if (spellCar == 2) {//出租车预约约车
                    map1.put("yuyueche_departtime", spellTime);

//                    if (ll_time_choosed.getVisibility() == View.GONE) {//未选择预约时间
//                        final SetTimeDialog setTimeDialog = new SetTimeDialog(getContext());
//                        setTimeDialog.tv_oncar_yes.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View view) {
//                                setTimeDialog.dismiss();
//                            }
//                        });
//                    } else {
//                        final IsGetOrderDialog dialog = new IsGetOrderDialog(getContext());
//                        dialog.tv_name.setText("小白");
//                        dialog.txt_queding.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View view) {
//                                ll_isgetorde_top.setVisibility(View.VISIBLE);
//                                ll_isgetorder_bottom.setVisibility(View.VISIBLE);
//
//                                ll_place.setVisibility(View.GONE);
//                                bottom_layout.setVisibility(View.GONE);
//                                img_show.setVisibility(View.GONE);
//                                location_bt.setVisibility(View.GONE);
//
//                                dialog.dismiss();
//                            }
//                        });
//                    }
                }
                String json1 = StringUtil.toJson(map1);
                try {
                    String data1 = AESCrypt.getInstance().encrypt(json1);
                    String d1 = StringUtil.replaceBlank(data1);
                    presenter.CallCar(d1);
                } catch (Exception ex) {
                }
                break;
            case R.id.ll_3callcar://网约车确认叫车

                Map map3 = new HashMap();
                map3.put("user_id", new UserUtil(getContext()).getUserId());
                map3.put("car_type", spellCar);
                map3.put("chufadi", MainActivity.shangche);
                map3.put("chufadijingdu", MainActivity.shangchelng);
                map3.put("chufadiweidu", MainActivity.shangchelat);
                map3.put("mudidi", MainActivity.quna);
                map3.put("mudijingdu", MainActivity.qunalng);
                map3.put("mudiweidu", MainActivity.qunalat);
                map3.put("shouji", new UserUtil(getContext()).getUser().mobile);
                map3.put("people", people3);
                if(spellCar == 5 || spellCar == 7){ // 网约车实时

                }else if(spellCar == 6 || spellCar == 8){ // 网约车预约
                    map3.put("yuyueche_departtime", spellTime3);
                }
                String json3 = StringUtil.toJson(map3);
                try {
                    String data1 = AESCrypt.getInstance().encrypt(json3);
                    String d1 = StringUtil.replaceBlank(data1);
                    presenter.CallCar(d1);
                } catch (Exception ex) {
                }
                break;
            case R.id.ll_cancel://已接单后取消订单
                Map map = new HashMap();
                map.put("order_id", dingdan.info.id);
                map.put("user_id", new UserUtil(this).getUserId());
                String json = StringUtil.toJson(map);
                try {
                    String data1 = AESCrypt.getInstance().encrypt(json);
                    String d = StringUtil.replaceBlank(data1);
                    OkHttpUtils.post()
                            .url(Const.BASE_URL + "api.php/Order/passengerCancel_order")
                            .addParams("args", d)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Call call, Exception e, int i) {
                                    Toast.makeText(MainActivity.this, "取消订单失败", Toast.LENGTH_SHORT).show();
                                }

                                @Override
                                public void onResponse(String s, int i) {
                                    JSONObject json;
                                    try {
                                        json = new JSONObject(s);
                                        int code = json.getInt("code");
                                        if (code == 200) {
                                            Toast.makeText(MainActivity.this, json.getString("message"), Toast.LENGTH_SHORT).show();
                                            clearMapAndDestanition();
                                        } else {
                                            Toast.makeText(MainActivity.this, json.getString("message"), Toast.LENGTH_SHORT).show();
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                } catch (Exception ex) {
                }
                break;
            case R.id.ll_oncar://我已上车
//                ll_isgetorde_top.setVisibility(View.GONE);
//                ll_isgetorder_bottom.setVisibility(View.GONE);
//
//                ll_place.setVisibility(View.VISIBLE);
//                bottom_layout.setVisibility(View.VISIBLE);
//                img_show.setVisibility(View.VISIBLE);
//                location_bt.setVisibility(View.VISIBLE);
                boardingDialog = new BoardingDialog(getContext());
                boardingDialog.tv_oncar_yes.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//我已上车
//                        ll_cancel.setVisibility(View.GONE);
//                        ll_isgetorder_bottom.setVisibility(View.GONE);
//                        ll_pay_bottom.setVisibility(View.VISIBLE);
//                        boardingDialog.dismiss();

                        Map map = new HashMap();
                        map.put("order_id", dingdan.info.id);
                        map.put("user_id", new UserUtil(MainActivity.this).getUserId());
                        map.put("queren", 1);
                        String json = StringUtil.toJson(map);
                        try {
                            String data1 = AESCrypt.getInstance().encrypt(json);
                            String d = StringUtil.replaceBlank(data1);
                            presenter.Boarding(d);
                        } catch (Exception ex) {
                        }
                    }
                });
                boardingDialog.tv_oncar_no.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//我未上车
//                        Map map = new HashMap();
//                        map.put("order_id", dingdan.info.id);
//                        map.put("user_id", new UserUtil(MainActivity.this).getUserId());
//                        map.put("queren", 2);
//                        String json = StringUtil.toJson(map);
//                        try {
//                            String data1 = AESCrypt.getInstance().encrypt(json);
//                            String d = StringUtil.replaceBlank(data1);
//                            presenter.Boarding(d);
//                        } catch (Exception ex) {
//                        }
                        boardingDialog.dismiss();
                    }
                });

                break;
            case R.id.ll_pay://我已下车并支付
                final PayDialog payDialog = new PayDialog(getContext());
                Glide.with(getContext()).load("http://47.93.113.101/Uploads/" +dingdan.info.avatar).into(payDialog.img_avatar);
                payDialog.tv_carnumber.setText(dingdan.info.carnumber);
                payDialog.tv_name.setText(dingdan.info.driver_realname);
                payDialog.tv_priceTotal.setText(dingdan.info.price);
                if(dingdan.info.driver.star == null){
                    payDialog.rating_star.setRating(5);
                }else{
                    payDialog.rating_star.setRating(Float.parseFloat(dingdan.info.driver.star));
                }
                payDialog.tv_pay_yes.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//确认支付
                        switch (channel) {
                            case "alipay":
                            case "wx":
                                pay();
                                break;
                            case "cash":
                                offPay();
                                break;
                        }
                        payDialog.dismiss();
                    }
                });
                payDialog.tv_pay_no.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//取消支付
                        payDialog.dismiss();
                    }
                });
                payDialog.tv_pay_detail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//支付明细
                        final PayDetailDialog payDetailDialog = new PayDetailDialog(getContext());
                        Map<String,String> map = new HashMap<String, String>();
//                        map.put("user_id",new UserUtil(getContext()).getUserId());
//                        map.put("type","1");
//                        map.put("order_id",dingdan.info.id);
//                        String json = StringUtil.toJson(map);
//                        String args = null;
//                        try {
//                            String data1 = AESCrypt.getInstance().encrypt(json);
//                            args = StringUtil.replaceBlank(data1);
//                        } catch (Exception ex) {
//                        }
//                        OkHttpUtils.post()
//                                .url(Const.BASE_URL+"api.php/Order/order_details")
//                            //    .params(map)
//                                .addParams("args", args)
//                                .build()
//                                .execute(new StringCallback() {
//                                    @Override
//                                    public void onError(Call call, Exception e, int i) {
//
//                                    }
//
//                                    @Override
//                                    public void onResponse(String s, int i) {
//                                        JSONObject json;
//                                        try {
//                                            json = new JSONObject(s);
//                                        } catch (JSONException e) {
//                                            e.printStackTrace();
//                                        }
//                                    }
//                                });
                        Glide.with(getContext()).load("http://47.93.113.101/Uploads/" +dingdan.info.avatar).into(payDetailDialog.img_avatar);
                        payDetailDialog.tv_carnumber.setText(dingdan.info.carnumber);
                        payDetailDialog.tv_name.setText(dingdan.info.driver_realname);
                        payDetailDialog.tv_priceTotal.setText(dingdan.info.price);
                        if(dingdan.info.driver.star == null){
                            payDetailDialog.rating_star.setRating(5);
                        }else{
                            payDetailDialog.rating_star.setRating(Float.parseFloat(dingdan.info.driver.star));
                        }
                        payDetailDialog.ll_call.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent it = new Intent();
                                it.setAction(Intent.ACTION_CALL);
                                it.setData(Uri.parse("tel:"+dingdan.info.driver_mobile));
                                startActivity(it);
                            }
                        });
                        payDetailDialog.tv_pay_yes.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                payDetailDialog.dismiss();
                            }
                        });
                        payDetailDialog.tv_pay_no.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {//取消支付
                                payDetailDialog.dismiss();
                            }
                        });
                    }
                });
                break;


        }
    }

    String people = "1";
    String people3 = "1";
    String people2 = "1";



    /**
     * 出租车支付
     */
    private String channel = "alipay";

    public void pay() {
        try {
            HashMap<String, String> map = new HashMap<>();
            AESCrypt aesCrypt = new AESCrypt();
            map.put("channel", channel);
            map.put("amount", dingdan.info.price);
            map.put("ordernum", dingdan.info.oid);
            map.put("subject", "快滴约车的订单");
            map.put("body", "快滴约车消费");
            String json = JsonUtils.toJson(map);
            String d = StringUtil.replaceBlank(aesCrypt.encrypt(json));

            OkHttpUtils.post()
                    .url(Const.BASE_URL + "api.php/pay/pay")
//                    .addParams("args", Util.replaceBlank(aesCrypt.encrypt(json)))
                    .addParams("args", d)
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Call call, Exception e, int i) {
                            Toast.makeText(getBaseContext(), "订单创建失败", Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onResponse(String response, int i) {
                            try {
                                JSONObject jsonObject = new JSONObject(response);
//                                if (jsonObject.getString("code").equals("200")) {
                                Pingpp.createPayment(MainActivity.this, response);
//                                    Toast.makeText(getApplicationContext(), "订单已完成", Toast.LENGTH_SHORT).show();
//                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
//            Log.i("GGGG","denglu加密==="+ Util.replaceBlank(aesCrypt.encrypt(json))+"     lainjie==="+CarAppConts.base_url+"login_with_reg&args="+Util.replaceBlank(aesCrypt.encrypt(json)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 线下支付
    public void offPay() {
        try {
            HashMap<String, String> map = new HashMap<>();
            AESCrypt aesCrypt = new AESCrypt();
            map.put("amount", dingdan.info.price);
            map.put("ordernum", dingdan.info.oid);
            map.put("channel", channel);
            String json = JsonUtils.toJson(map);
            String d = StringUtil.replaceBlank(aesCrypt.encrypt(json));
            OkHttpUtils.post()
                    .url(Const.BASE_URL + "api.php/order/cash")
                    .addParams("args", d)
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Call call, Exception e, int i) {
                            Toast.makeText(getBaseContext(), "线下支付失败", Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onResponse(String response, int i) {
                            try {
                                JSONObject jsonObject = new JSONObject(response);
                                if (jsonObject.getString("code").equals("200")) {
                                    Toast.makeText(getApplicationContext(), "现金支付成功，等待司机确认", Toast.LENGTH_SHORT).show();
                                    clearMapAndDestanition();
//                                    ll_pay_bottom.setVisibility(View.GONE);
                                } else{
                                    Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
//            Log.i("GGGG","denglu加密==="+ Util.replaceBlank(aesCrypt.encrypt(json))+"     lainjie==="+CarAppConts.base_url+"login_with_reg&args="+Util.replaceBlank(aesCrypt.encrypt(json)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //支付页面返回处理
        if (requestCode == Pingpp.REQUEST_CODE_PAYMENT) {
            if (resultCode == Activity.RESULT_OK) {
                String result = data.getExtras().getString("pay_result");

                // 处理返回值
                // "success" - 支付成功
                // "fail"    - 支付失败
                // "cancel"  - 取消支付
                // "invalid" - 支付插件未安装（一般是微信客户端未安装的情况）
                switch (result) {
                    case "success":
                        Toast.makeText(getApplicationContext(), "支付成功", Toast.LENGTH_SHORT).show();

                        StrokeInfor strokeInfor = new StrokeInfor();
                        strokeInfor.id = dingdan.info.id;
                        Intent it = new Intent();
                        Bundle bundle1 = new Bundle();
                        bundle1.putSerializable("item", strokeInfor);
                        it.putExtras(bundle1);
                        it.setClass(getContext(), PingJiaSiJiActivity.class);
                        startActivity(it);

                        clearMapAndDestanition();
                        break;
                    case "fail":
                        Toast.makeText(getApplicationContext(), "支付失败", Toast.LENGTH_SHORT).show();
                        break;
                    case "cancel":
                        Toast.makeText(getApplicationContext(), "取消支付", Toast.LENGTH_SHORT).show();
                        break;
                    case "invalid":
                        Toast.makeText(getApplicationContext(), "支付插件未安装", Toast.LENGTH_SHORT).show();
                        break;
                }

                String errorMsg = data.getExtras().getString("error_msg"); // 错误信息
                String extraMsg = data.getExtras().getString("extra_msg"); // 错误信息
                String test = "";
//                showMsg(result, errorMsg, extraMsg);
            }
        }

        if (requestCode == 1021 && resultCode == 2010) {
//            cid = data.getStringExtra("cid");
//            youhuiquan.setText(data.getStringExtra("msg"));

        }
    }

    /**
     * 回复初始界面
     */
    public void clearMapAndDestanition() {
        bottom_layout.setVisibility(View.VISIBLE);
        ll_place.setVisibility(View.VISIBLE);
        ll_isgetorder_bottom.setVisibility(View.GONE);
        ll_isgetorde_top.setVisibility(View.GONE);
        ll_pay_bottom.setVisibility(View.GONE);

        tv_qunaer.setText("你要去哪儿");
        MainActivity.quna = "";
        MainActivity.qunalat = "";
        MainActivity.qunalng = "";

        // dingdan = null;

        aMap.clear();


        LatLng latLng = new LatLng(MainActivity.lat, MainActivity.lng);
        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 19));

        rlTag.setVisibility(View.VISIBLE);
    }

    /*顺风车*/
    @OnClick({R.id.ll_in_city, R.id.ll_through_city, R.id.rl_stroke, R.id.rl_stroke_commonly, R.id.ll_stroke_detail, R.id.ll_stroke_commonly_detail})
    public void downwindCar_OnClick(View view) {
        switch (view.getId()) {
            case R.id.ll_in_city://市内行程
                inOrthrough = 1;
                img_in_city.setBackgroundResource(R.drawable.shinei);
                tv_in_city.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_in_city.setBackgroundResource(R.drawable.shape_3);
                img_through_city.setBackgroundResource(R.drawable.kuacheng_hui);
                tv_through_city.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_through_city.setBackgroundResource(R.drawable.shape_6);
                break;
            case R.id.ll_through_city://跨城行程
                inOrthrough = 2;
                img_in_city.setBackgroundResource(R.drawable.shinei_hui);
                tv_in_city.setTextColor(ContextCompat.getColor(this, R.color.txt_black));
                ll_in_city.setBackgroundResource(R.drawable.shape_6);
                img_through_city.setBackgroundResource(R.drawable.kuacheng);
                tv_through_city.setTextColor(ContextCompat.getColor(this, R.color.theme_white));
                ll_through_city.setBackgroundResource(R.drawable.shape_3);
                break;
            case R.id.rl_stroke://已发布行程
                startActivity(StrokeAllActivity.class, new Bun().putString("tag", "2").ok());
                break;
            case R.id.rl_stroke_commonly://未发布行程
                startActivity(StrokeAllActivity.class, new Bun().putString("tag", "2").ok());
                break;
            case R.id.ll_stroke_detail:
                startActivity(DownwindWaitActivity.class);
                break;
            case R.id.ll_stroke_commonly_detail:
                startActivity(DownwindReceivedActivity.class);
                break;
        }
    }

    /*网约车*/
    @OnClick({R.id.img_ordinary_car, R.id.img_special_car, R.id.ll_special_car, R.id.ll_ordinary_car})
    public void netCar_OnClick(View view) {
        switch (view.getId()) {
            case R.id.ll_special_car://普通车
                ordinaryOrspecial = 0;
                ll_ordinary_car.setVisibility(View.VISIBLE);
                ll_special_car.setVisibility(View.GONE);
                break;
            case R.id.ll_ordinary_car://专车
                ordinaryOrspecial = 1;
                ll_ordinary_car.setVisibility(View.GONE);
                ll_special_car.setVisibility(View.VISIBLE);
                break;
        }
    }

    @OnClick({R.id.ll_qunaer})
    public void address_OnClick(View view) {
        switch (view.getId()) {
            case R.id.ll_qunaer:
                if(flag_carType == 1){
                    Const.downTag = -1;
                }
                intent = new Intent(getContext(), DidianActivity.class);
                intent.putExtra("address", place);
                intent.putExtra("citycz", city);
                intent.putExtra("biaoshi", "xiache");
                startActivity(intent);
//                if (new UserUtil(getContext()).isLogin()) {
//
//                } else {
//                   // mainActivity.dengludialog();
//                }
                break;
        }
    }

    @Override
    protected void initThings(Bundle savedInstanceState) {
        super.initThings(savedInstanceState);
        imgBack.setImageResource(R.drawable.juxing12);

        initSlidingMenu();

        // 注册广播接收器
        registerBoradcastReceiver();

        flag_carType = 0;
        inOrthrough = 1;
        ordinaryOrspecial = 0;
        spellCar = 1;

        bottom_layout = (LinearLayout) findViewById(R.id.bottom_layout);
        bottom_layout_downwind = (LinearLayout) findViewById(R.id.bottom_layout_downwind);

        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(savedInstanceState);

        initamap();

        mRegeocodeTask = new RegeocodeTask(getContext());//为该对象赋值
        mRegeocodeTask.setOnLocationGetListener(this);//设置监听器

    }



    @Override
    protected void onResume() {
        super.onResume();
        presenter.MyStroke();
        /**
         * 获取附近车辆数量
         */
        getNearCar();

        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();

        if (MainActivity.shangche.equals("")) {
            ll_callcar.setVisibility(View.GONE);
        } else {
            tv_shangche.setText(MainActivity.shangche);
        }
        if (MainActivity.quna.equals("")) {
            ll_callcar.setVisibility(View.GONE);
        } else {
            tv_qunaer.setText(MainActivity.quna);
            ll_callcar.setVisibility(View.VISIBLE);
        }
        if (!MainActivity.shangche.equals("") && !MainActivity.quna.equals("")) {
            myLatLonPoint = new LatLonPoint(Double.parseDouble(MainActivity.shangchelat), Double.parseDouble(MainActivity.shangchelng));
            youLatLonPoint = new LatLonPoint(Double.parseDouble(MainActivity.qunalat), Double.parseDouble(MainActivity.qunalng));
            rlTag.setVisibility(View.GONE);
            getMapRoute();
        } else {
            rlTag.setVisibility(View.VISIBLE);
        }

        bottom_layout.setVisibility(View.VISIBLE);
        if(flag_carType ==1){
            if(!(Const.downTag == -1)){
                bottom_layout_downwind.setVisibility(View.VISIBLE);
//            presenter.MyStroke();
            }
            if(Const.downTag == 1){
                bottom_layout_downwind.setVisibility(View.GONE);
//            bottom_layout.setVisibility(View.VISIBLE);
                if(dingdan == null){
                    carRunning();
                }
            }else if(Const.downTag == -1||Const.downTag == 0){
                bottom_layout_downwind.setVisibility(View.GONE);
                imgBack.setImageResource(R.drawable.juxing12);
                tv_title.setText(city);
                imgBack.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onBackPressed();
                    }
                });
            }
        }


//        Map map = new HashMap();
//        map.put("start_lat", MainActivity.shangchelat);
//        map.put("start_lng", MainActivity.shangchelng);
//        map.put("end_lat", MainActivity.qunalat);
//        map.put("end_lng", MainActivity.qunalng);
//        String json = StringUtil.toJson(map);
//        try {
//            String data1 = AESCrypt.getInstance().encrypt(json);
//            String d = StringUtil.replaceBlank(data1);
//          //  presenter.EstimatedFare(d);
//        } catch (Exception ex) {
//        }

        User user = new UserUtil(this).getUser();
        if(new UserUtil(this).isLogin()){
            tv_username.setText(user.username);
            tv_phone.setText(user.mobile);
            Glide.with(this)
                    .load(user.avatar)
                    .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                    .centerCrop()
                    .into(img_title);
        }
    }

    public void initCarLayout(){
        if (flag_carType == 0 || flag_carType == 2) { //出租车、网约车

            switch (rentState) {
                case 0://未叫车
                    bottom_layout_downwind.setVisibility(View.GONE);

                    ll_isgetorde_top.setVisibility(View.GONE);
                    ll_isgetorder_bottom.setVisibility(View.GONE);

                    ll_place.setVisibility(View.VISIBLE);
                    bottom_layout.setVisibility(View.VISIBLE);
                    img_show.setVisibility(View.VISIBLE);
                    location_bt.setVisibility(View.VISIBLE);
                    tv_title.setText(city);
//                    ll_time_choosed.setVisibility(View.GONE);
//                    ll_time_nochoose.setVisibility(View.VISIBLE);

                    ll_pay_bottom.setVisibility(View.GONE);

//            if(realtimeOradvance == 0){//实时约车
//                tv_timetype.setText("预计时间");
//                ll_time_choosed.setVisibility(View.VISIBLE);
//                ll_time_nochoose.setVisibility(View.GONE);
//            }else if(realtimeOradvance == 1){//预约约车
//                tv_timetype.setText("选择时间");
//                ll_time_choosed.setVisibility(View.GONE);
//                ll_time_nochoose.setVisibility(View.VISIBLE);
//            }
                    break;
//                case 1://司机已接单，待上车
//                    ll_isgetorde_top.setVisibility(View.VISIBLE);
//                    ll_isgetorder_bottom.setVisibility(View.VISIBLE);
////                    tv_driver_name.setText(dingdan.info.driver_realname);
////                    tv_driver_carnumber.setText(dingdan.info.carnumber);
//
//                    ll_place.setVisibility(View.GONE);
//                    bottom_layout.setVisibility(View.GONE);
//                    img_show.setVisibility(View.GONE);
//                    break;
                case 2://行驶中
                    ll_isgetorde_top.setVisibility(View.VISIBLE);
                    ll_isgetorder_bottom.setVisibility(View.VISIBLE);
//                    tv_driver_name.setText(dingdan.info.driver_realname);
//                    tv_driver_carnumber.setText(dingdan.info.carnumber);

                    ll_place.setVisibility(View.GONE);
                    bottom_layout.setVisibility(View.GONE);
                    img_show.setVisibility(View.GONE);

                    ll_cancel.setVisibility(View.GONE);
                    tv_getInCar.setText("行驶中");
//                    tv_driveringContent1.setVisibility(View.GONE);
//                    tv_driveringContent2.setVisibility(View.GONE);
//                    tv_driveringContent1.setText(" ");
//                    tv_driveringContent2.setText(" ");
                    ll_oncar.setEnabled(false);
                    break;
//                case 3://行驶完成，待支付
//                    ll_isgetorde_top.setVisibility(View.VISIBLE);
//                    ll_isgetorder_bottom.setVisibility(View.VISIBLE);
////                    tv_driver_name.setText(dingdan.info.driver_realname);
////                    tv_driver_carnumber.setText(dingdan.info.carnumber);
//
//                    ll_place.setVisibility(View.GONE);
//                    bottom_layout.setVisibility(View.GONE);
//                    img_show.setVisibility(View.GONE);
//
//                    ll_pay_bottom.setVisibility(View.VISIBLE);
//                    tv_money2.setText(dingdan.info.price);
//                    break;
            }

        }else if (flag_carType == 1) {//顺风车
            ll_isgetorde_top.setVisibility(View.GONE);
            ll_isgetorder_bottom.setVisibility(View.GONE);

            ll_place.setVisibility(View.VISIBLE);
            bottom_layout.setVisibility(View.VISIBLE);
            img_show.setVisibility(View.GONE);
//            location_bt.setVisibility(View.GONE);
            if(Const.downTag == 0){
                img_show.setVisibility(View.VISIBLE);
            }

            Log.e("downTag--->",Const.downTag+"");
            if(Const.downTag == -1){
                imgBack.setImageResource(R.drawable.tuichu);
                tv_title.setText("确认行程发布");
                bottom_layout_downwind.setVisibility(View.VISIBLE);
                bottom_layout.setVisibility(View.GONE);
                imgBack.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        bottom_layout_downwind.setVisibility(View.GONE);
                        Const.downTag = 0;

                        ll_isgetorde_top.setVisibility(View.GONE);
                        ll_isgetorder_bottom.setVisibility(View.GONE);

                        ll_place.setVisibility(View.VISIBLE);
                        bottom_layout.setVisibility(View.VISIBLE);
                        img_show.setVisibility(View.VISIBLE);
                        location_bt.setVisibility(View.VISIBLE);

                        imgBack.setImageResource(R.drawable.juxing12);
                        tv_title.setText(city);

                        imgBack.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                onBackPressed();
                            }
                        });
                    }
                });
            }

//            if(Const.downTag == -1||Const.downTag == 0) {
//                bottom_layout_downwind.setVisibility(View.VISIBLE);
//                bottom_layout.setVisibility(View.GONE);
//            }else{
//                bottom_layout_downwind.setVisibility(View.GONE);
//            }

            Map<String,String> map = new HashMap<>();
            // map.put("kilometers",mile);
            map.put("kilometers",milefloat/1000+"");
            map.put("type",inOrthrough+"");
            map.put("car_type","1");
            map.put("start_lat",MainActivity.shangchelat+"");
            map.put("start_lng",MainActivity.shangchelng+"");
            map.put("end_lat", MainActivity.qunalat);
            map.put("end_lng",MainActivity.qunalng );
//            Log.e("顺风车shangchelat-------",shangchelat);
//            Log.e("顺风车shangchelng--",shangchelng);
//            Log.e("顺风车qunalat--",qunalat);
//            Log.e("顺风车qunalng--",qunalng);
            Log.e("顺风车kilometers--",milefloat/1000+"");
            String json = JsonUtils.toJson(map);
            String data1 = null;
            try {
                data1 = AESCrypt.getInstance().encrypt(json);
                String d1 = StringUtil.replaceBlank(data1);
                OkHttpUtils.post()
                        .url(Const.BASE_URL+"api.php/free/carpool_price")
                        .addParams("args",d1)
                        .build()
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Call call, Exception e, int i) {
                                Log.e("顺风车onError--",e.getMessage());
                                e.printStackTrace();
                            }

                            @Override
                            public void onResponse(String s, int i) {
                                JSONObject json;
                                try {
                                    json = new JSONObject(s);
                                    int code = json.getInt("code");
                                    if(code == Const.OK){
                                        tv2Price.setText(json.optString("datas"));
                                        Log.e("顺风车onResponse--",json.optString("datas"));
                                    }else{
                                        Log.e("顺风车onResponse--","获取顺风车预估价格失败");
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
            } catch (Exception e) {
                e.printStackTrace();
            }

            ll2People.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final NumberPicker picker = new NumberPicker(MainActivity.this);
                    picker.setRange(1, 4,"4");//数字范围
                    picker.setSelectedItem(1);
//                picker.setLabel("人");
                    picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
                        @Override
                        public void onOptionPicked(String option) {
//                        if(option.equals("4人")) {
//                            people = "4";
//                            tv_people.setText(option);
//                        }else{
                            people2 = option;
                            tv2People.setText(option);
//                        }

//                        if (canpeople)
//                            getMoney();
                        }
                    });
                    picker.show();
                }
            });
            ll2Time.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ArrayList<String> firstList = new ArrayList<String>();
                    firstList.add("今天");
                    firstList.add("明天");
                    firstList.add("后天");
                    ArrayList<ArrayList<String>> secondList = new ArrayList<ArrayList<String>>();
                    ArrayList<String> secondListItem = new ArrayList<String>();
                    for (int i = 0; i < 24; i++) {
                        secondListItem.add(DateUtils.fillZero(i) + "点");
                    }
                    secondList.add(secondListItem);//对应今天
                    secondList.add(secondListItem);//对应明天
                    secondList.add(secondListItem);//对应后天
                    ArrayList<ArrayList<ArrayList<String>>> thirdList = new ArrayList<ArrayList<ArrayList<String>>>();
                    ArrayList<ArrayList<String>> thirdListItem1 = new ArrayList<ArrayList<String>>();
                    ArrayList<String> thirdListItem2 = new ArrayList<String>();
                    for (int i = 0; i < 60; i++) {
                        thirdListItem2.add(DateUtils.fillZero(i) + "分");
                    }
                    for (int i = 0; i < 24; i++) {
                        thirdListItem1.add(thirdListItem2);//对应0-23点
                    }
                    thirdList.add(thirdListItem1);//对应今天
                    thirdList.add(thirdListItem1);//对应明天
                    thirdList.add(thirdListItem1);//对应后天

//        LinkagePicker picker = new LinkagePicker(this, firstList, secondList);//二级联动选择器构造函数
                    LinkagePicker picker = new LinkagePicker(MainActivity.this, firstList, secondList,thirdList);//三级联动选择器构造函数

                    picker.setSelectedItem("明天", "9点","30分");
                    picker.setOnLinkageListener(new LinkagePicker.OnLinkageListener() {

                        @Override
                        public void onPicked(String first, String second, String third) {
//                toast(first + "-" + second);
                            //  toast(first + "-" + second + "-" + third);



                            spellTime2 = first + " " + second.substring(0, second.length() - 1) + ":" + third.substring(0, second.length() - 1) + ":00";

                            ToolsUtil.print("----", "叫车时间：" + spellTime3);

                            tv2Time.setText(second.substring(0, second.length() - 1) + ":" + third.substring(0, second.length() - 1));
                            tv2TimeDay.setText(first);

                        }
                    });
                    picker.show();
                }
            });

            ll2Release.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(!StringUtil.isEmpty(spellTime2)) {
                        Map map3 = new HashMap();
                        map3.put("user_id", new UserUtil(getContext()).getUserId());
                        map3.put("chufadi", MainActivity.shangche);
                        map3.put("chufadijingdu", MainActivity.shangchelng);
                        map3.put("chufadiweidu", MainActivity.shangchelat);
                        map3.put("mudidi", MainActivity.quna);
                        map3.put("mudijingdu", MainActivity.qunalng);
                        map3.put("mudiweidu", MainActivity.qunalat);
                        map3.put("shouji", new UserUtil(getContext()).getUser().mobile);
                        map3.put("yuyueche_departtime", spellTime2);
                        map3.put("car_type", "3");
                        map3.put("people", people2);
                        map3.put("is_cross_city", inOrthrough);
                        String json3 = StringUtil.toJson(map3);
                        try {
                            String data1 = AESCrypt.getInstance().encrypt(json3);
                            String d1 = StringUtil.replaceBlank(data1);
                            presenter.CallCar2(d1);
                        } catch (Exception ex) {
                        }
                    }else{
                        toast("请选择出发时间");
                    }
                }
            });



//            ll_release.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {//发布行程
//                    final ReleaseDialog releaseDialog = new ReleaseDialog(getContext());
//                    releaseDialog.tv_oncar_yes.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            releaseDialog.dismiss();
//                            startActivity(DownwindWaitActivity.class);
//                        }
//                    });
//                }
//            });

        }
    }

    /**
     * 获取附近车辆
     */
    public void getNearCar() {
        Map<String, String> map1 = new HashMap<>();
//        map1.put("departure_lat", MainActivity.shangchelat);
//        map1.put("departure_lng", MainActivity.shangchelng);
        map1.put("departure_lat", MainActivity.shangchelng);
        map1.put("departure_lng", MainActivity.shangchelat);
        String json1 = JsonUtils.toJson(map1);
        String data2 = null;
        try {
            data2 = AESCrypt.getInstance().encrypt(json1);
            String d2 = StringUtil.replaceBlank(data2);

            OkHttpUtils.post()
                    .url(Const.BASE_URL + "api.php/Order/numCar")
                    .addParams("args", d2)
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Call call, Exception e, int i) {

                        }

                        @Override
                        public void onResponse(String response, int i) {
                            JSONObject json;
                            try {
                                json = new JSONObject(response);
                                int code = json.getInt("code");
                                if (code == 200) {
                                    String str = json.getString("datas");
                                    txtNearCarNum.setText(str);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });

//            String url = Const.BASE_URL+"api.php/Order/numCar";
//            OkHttpClient okHttpClient = new OkHttpClient();
//            //   Request request = new Request.Builder().url(url).addParams("args", d).build();
//            FormBody body = new FormBody.Builder()
//                    .add("args",d2)
//                    .build();
//            //创建请求对象
//            Request request = new Request.Builder()
//                    .post(body)
//                    .url(url)
//                    .build();
//            //创建回调对象
//            Call call = okHttpClient.newCall(request);
//            //发起请求
//            call.enqueue(new Callback() {
//                @Override
//                public void onFailure(Call call, IOException e) {
//                    Log.e("result", e.getMessage());
//                }
//
//                @Override
//                public void onResponse(Call call, Response response) throws IOException {
//                    final String content = response.body().string();
//                    //返回的时候在子线程，需要handler更新UI
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            JSONObject json;
//                            try {
//                                json = new JSONObject(content);
//                                int code = json.getInt("code");
//                                if(code == 200){
//                                    String str = json.getString("datas");
//                                    txtNearCarNum.setText(str);
//                                    ToolsUtil.print("----","获取附近车辆成功："+str);
//                                }
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    });
//                }
//            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();

        deactivate();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
//        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
//        mMapView.onDestroy();
        if (mMapView != null) { //这里不加判断报了空指针异常
            //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
            mMapView.onDestroy();
        }
        //需要在系统 onDestroy() 方法中销毁定位对象。
        if (null != mlocationClient) {
            mlocationClient.onDestroy();
        }

        unregisterReceiver(mBroadcastReceiver);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mMapView.onSaveInstanceState(outState);
    }

    private void initamap() {

        if (aMap == null) {
            //创建地图对象的控制器（初始化地图）
            aMap = mMapView.getMap();

            aMap.moveCamera(CameraUpdateFactory.zoomTo(18));//设置缩放等级
            // 设置定位监听
            aMap.setLocationSource(this);
            // 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
            aMap.setMyLocationEnabled(true);


            // 自定义系统定位小蓝点
            MyLocationStyle myLocationStyle = new MyLocationStyle();
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory
                    //                   .fromResource(R.drawable.yongchebiaoji));// 设置小蓝点的图标
                    //    .fromResource(R.drawable.location_marker));// 设置小蓝点的图标
                    .fromResource(R.drawable.lsdwd));// 设置小蓝点的图标

//            myLocationStyle.strokeColor(Color.BLACK);// 设置圆形的边框颜色
//            myLocationStyle.radiusFillColor(Color.argb(100, 0, 0, 180));// 设置圆形的填充颜色
            myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0));// 设置圆形的边框颜色
            myLocationStyle.radiusFillColor(Color.argb(0, 0, 0, 0));// 设置圆形的填充颜色
            myLocationStyle.strokeWidth(1.0f);// 设置圆形的边框粗细
            aMap.setMyLocationStyle(myLocationStyle);

            aMap.setLocationSource(this);// 设置定位资源。如果不设置此定位资源则定位按钮不可点击。并且实现activate激活定位,停止定位的回调方法
            aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
            aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false


            mUiSettings = aMap.getUiSettings();
            mUiSettings.setZoomControlsEnabled(false);

            mUiSettings.setMyLocationButtonEnabled(false); // 是否显示默认的定位按钮

            aMap.setOnCameraChangeListener(this);
        }
    }

    /**
     * 激活定位
     */
    @Override
    public void activate(OnLocationChangedListener listener) {
        mListener = listener;
        if (mlocationClient == null) {
            //初始化定位
            mlocationClient = new AMapLocationClient(this);
            //初始化定位参数
            mLocationOption = new AMapLocationClientOption();
            //设置定位回调监听
            mlocationClient.setLocationListener(this);
            //设置为高精度定位模式
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            //设置定位参数
            mlocationClient.setLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            mlocationClient.startLocation();//启动定位
        }
    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate() {
        mListener = null;
        if (mlocationClient != null) {
            mlocationClient.stopLocation();
//            mlocationClient.onDestroy();
        }
//        mlocationClient = null;
    }

    /**
     * 定位成功后回调函数（在定位回调中设置显示定位小蓝点）
     */
    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (mListener != null && amapLocation != null) {
            if (amapLocation != null && amapLocation.getErrorCode() == 0) {
                mListener.onLocationChanged(amapLocation);// 显示系统小蓝点

                amapLocation.getLocationType();//获取当前定位结果来源，如网络定位结果，详见定位类型表
                lat = amapLocation.getLatitude();//获取纬度
                lng = amapLocation.getLongitude();//获取经度
                amapLocation.getAccuracy();//获取精度信息
                place = amapLocation.getAddress();
                city = amapLocation.getCity();
                shangche = place;
                shangchelat = Double.toString(lat);
                shangchelng = Double.toString(lng);
                tv_title.setText(city);
                tv_shangche.setText(place);
                mlocationClient.stopLocation();

//                addMarkerToMap();//绘制自定义 Marker
            } else {
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
                Log.e("AmapErr", errText);
            }
        }
    }

    public void addMarkerToMap() {
        LatLng latLng = new LatLng(lat, lng);

        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(latLng);
        //  markerOption.title("西安市").snippet("西安市：34.341568, 108.940174");

        markerOption.draggable(true);//设置Marker可拖动
        markerOption.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
                .decodeResource(getResources(), R.drawable.fujincheliang)));
        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
        //      markerOption.setFlat(true);//设置marker平贴地图效果

        final Marker marker = aMap.addMarker(markerOption);

    }

    /**
     * 预约约车_选择时间
     */
    public void onLinkagePicker() {
        ArrayList<String> firstList = new ArrayList<String>();
        firstList.add("今天");
        firstList.add("明天");
        firstList.add("后天");
        ArrayList<ArrayList<String>> secondList = new ArrayList<ArrayList<String>>();
        ArrayList<String> secondListItem = new ArrayList<String>();
        for (int i = 0; i < 24; i++) {
            secondListItem.add(DateUtils.fillZero(i) + "点");
        }
        secondList.add(secondListItem);//对应今天
        secondList.add(secondListItem);//对应明天
        secondList.add(secondListItem);//对应后天
        ArrayList<ArrayList<ArrayList<String>>> thirdList = new ArrayList<ArrayList<ArrayList<String>>>();
        ArrayList<ArrayList<String>> thirdListItem1 = new ArrayList<ArrayList<String>>();
        ArrayList<String> thirdListItem2 = new ArrayList<String>();
        for (int i = 0; i < 60; i++) {
            thirdListItem2.add(DateUtils.fillZero(i) + "分");
        }
        for (int i = 0; i < 24; i++) {
            thirdListItem1.add(thirdListItem2);//对应0-23点
        }
        thirdList.add(thirdListItem1);//对应今天
        thirdList.add(thirdListItem1);//对应明天
        thirdList.add(thirdListItem1);//对应后天

//        LinkagePicker picker = new LinkagePicker(this, firstList, secondList);//二级联动选择器构造函数
        LinkagePicker picker = new LinkagePicker(this, firstList, secondList,thirdList);//三级联动选择器构造函数

        picker.setSelectedItem("明天", "9点","30分");
        picker.setOnLinkageListener(new LinkagePicker.OnLinkageListener() {

            @Override
            public void onPicked(String first, String second, String third) {
//                toast(first + "-" + second);
                //  toast(first + "-" + second + "-" + third);

                if(spellCar==6||spellCar == 8){
                    ll_3time_choosed.setVisibility(View.VISIBLE);
                    ll_3time_nochoose.setVisibility(View.GONE);

                    tv_3time_realtime_number.setVisibility(View.GONE);
                    tv_3time_realtime_min.setVisibility(View.GONE);
                    tv_3time_advance.setVisibility(View.VISIBLE);
                    tv_3time_advance.setText(first + "-" + second + "-" + third);

                    spellTime3 = first + " " + second.substring(0, second.length() - 1) + ":" + third.substring(0, second.length() - 1) + ":00";

                    ToolsUtil.print("----", "叫车时间：" + spellTime3);
                }else if(spellCar == 2) {
                    ll_time_choosed.setVisibility(View.VISIBLE);
                    ll_time_nochoose.setVisibility(View.GONE);

                    tv_time_realtime_number.setVisibility(View.GONE);
                    tv_time_realtime_min.setVisibility(View.GONE);
                    tv_time_advance.setVisibility(View.VISIBLE);
                    tv_time_advance.setText(first + "-" + second + "-" + third);

                    spellTime = first + " " + second.substring(0, second.length() - 1) + ":" + third.substring(0, second.length() - 1) + ":00";

                    ToolsUtil.print("----", "叫车时间：" + spellTime);
                }
            }
        });
        picker.show();
    }

    private String spellTime="";
    private String spellTime3="";
    private String spellTime2="";

    /**
     * 驾车出行路线规划
     */
    public void getMapRoute() {
        routeSearch = new RouteSearch(getContext());    //        35.0799687989,118.3277585486
        // fromAndTo包含路径规划的起点和终点，drivingMode表示驾车模式
        // 第三个参数表示途经点（最多支持16个），第四个参数表示避让区域（最多支持32个），第五个参数表示避让道路
        RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(myLatLonPoint, youLatLonPoint);
        RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "");
        routeSearch.calculateDriveRouteAsyn(query);

        routeSearch.setRouteSearchListener(new RouteSearch.OnRouteSearchListener() {
            @Override
            public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {
                Log.i("GGGG", "onDriveRouteSearched===" + i + "    busRouteResult=" + busRouteResult);
            }

            @Override
            public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int i) {
                // 驾车模式回调
                Log.i("GGGG", "onDriveRouteSearched===" + i + "    driveRouteResult=" + driveRouteResult);
                if (i == 1000) {
                    if (driveRouteResult != null && driveRouteResult.getPaths() != null
                            && driveRouteResult.getPaths().size() > 0) {
                        driveRouteResults = driveRouteResult;
                        DrivePath drivePath = driveRouteResult.getPaths().get(0);
                        aMap.clear();// 清理地图上的所有覆盖物

                        drivingRouteOverlay = new DrivingRouteOverlay(
                                getContext(), aMap, drivePath, driveRouteResult.getStartPos(),
                                driveRouteResult.getTargetPos());//路线覆盖
                        drivingRouteOverlay.removeFromMap();
                        drivingRouteOverlay.addToMap();
//                        if (zoom){
                        drivingRouteOverlay.zoomToSpan();
//                            zoom = false;
//                        }

                        int dis = (int) drivePath.getDistance();//距离(米)
                        int dur = (int) drivePath.getDuration();//预计时间
                        int taxiCost = (int) driveRouteResults.getTaxiCost();//预计价格

                        mile = drivePath.getDistance() + "";
                        milefloat = drivePath.getDistance();
                        String milefloatstr = milefloat/1000+"";

                        des = AMapUtil.getFriendlyTime(dur);
//                        ll_time_choosed.setVisibility(View.VISIBLE);
//                        ll_time_nochoose.setVisibility(View.GONE);

//                        if(spellCar == 1 || spellCar == 2) {
                        tv_money.setText(taxiCost + "元");
                        if (realtimeOradvance == 1||realtimeOradvance == 5) {//实时约车
                            ll_time_choosed.setVisibility(View.VISIBLE);
                            ll_time_nochoose.setVisibility(View.GONE);
                            ll_3time_choosed.setVisibility(View.VISIBLE);
                            ll_3time_nochoose.setVisibility(View.GONE);
                        } else if (realtimeOradvance == 6||realtimeOradvance == 2 ) {//预约约车
                            ll_time_choosed.setVisibility(View.GONE);
                            ll_time_nochoose.setVisibility(View.VISIBLE);
                            ll_3time_choosed.setVisibility(View.GONE);
                            ll_3time_nochoose.setVisibility(View.VISIBLE);
                        }
                        tv_time_realtime_number.setVisibility(View.VISIBLE);
                        tv_time_realtime_min.setVisibility(View.GONE);
                        tv_time_advance.setVisibility(View.GONE);
                        tv_time_realtime_number.setText(des);
//                        }else if(spellCar == 5 || spellCar == 6 || spellCar == 7 || spellCar == 8 ){
                        tv_3money.setText(taxiCost + "元");
                        tv_3time_realtime_number.setVisibility(View.VISIBLE);
                        tv_3time_realtime_min.setVisibility(View.GONE);
                        tv_3time_advance.setVisibility(View.GONE);
                        tv_3time_realtime_number.setText(des);
//                        tv_3timetype.setVisibility(View.VISIBLE);
//                        tv_timetype.setVisibility(View.VISIBLE);
//                        tv_3timetype.setText("预计时间");
//                        tv_timetype.setText("预计时间");
//                        }
                    } else {
                        Toast.makeText(getContext(), "没有查出对应的路径", Toast.LENGTH_LONG);

                    }
                } else {
                    Toast.makeText(getContext(), "其他未知错误", Toast.LENGTH_LONG).show();

                }

                initCarLayout();
            }

            @Override
            public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {
                Log.i("GGGG", "onDriveRouteSearched===" + i + "    walkRouteResult=" + walkRouteResult);
            }
        });
    }

    int time = 60;
    private Handler handlerWaitting = new Handler();

    Runnable waittingRunnable = new Runnable() {
        @Override
        public void run() {
            if (time >= 1) {
                time--;
                cancelCallCarDialog.tv_waiting.setText(time + "");
                handlerWaitting.postDelayed(waittingRunnable, 1000);
            } else {
                cancelCallCarDialog.dismiss();
                Map map = new HashMap();
                // map.put("order_id", 3035);
                map.put("order_id", dingdan.info.id);
                map.put("user_id", new UserUtil(getContext()).getUserId());
                String json = StringUtil.toJson(map);
                try {
                    String data1 = AESCrypt.getInstance().encrypt(json);
                    String d = StringUtil.replaceBlank(data1);
                    presenter.CancelCallCar(d);
                } catch (Exception ex) {
                }
                time = 60;
            }
        }
    };

    Thread thread = new Thread(waittingRunnable);
    CallCarDialogNoWaitting dialogNoWaitting;

    @Override
    public void callCarSuccess(Dingdan str) {
        toast("叫车成功");
        dingdan = str;
        if(spellCar == 1 || spellCar == 5) {
            cancelCallCarDialog = new CancelCallCarDialog(getContext());
            handlerWaitting.postDelayed(waittingRunnable, 1000);

//        Dingdan dingdan1 = dingdan;
            cancelCallCarDialog.tv_oncar_yes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    cancelCallCarDialog.dismiss();

                    time = 60;

                    handlerWaitting.removeCallbacks(waittingRunnable);

                    Map map = new HashMap();
                    // map.put("order_id", 3035);
                    map.put("order_id", dingdan.info.id);
                    map.put("user_id", new UserUtil(getContext()).getUserId());
                    String json = StringUtil.toJson(map);
                    try {
                        String data1 = AESCrypt.getInstance().encrypt(json);
                        String d = StringUtil.replaceBlank(data1);
                        presenter.CancelCallCar(d);
                    } catch (Exception ex) {
                    }
                }
            });
        }else{
            dialogNoWaitting = new CallCarDialogNoWaitting(getContext());
            dialogNoWaitting.tv_oncar_yes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialogNoWaitting.dismiss();
                }
            });

        }

        if(Const.downTag == -1) {
            bottom_layout_downwind.setVisibility(View.GONE);
            Const.downTag = 1;
            imgBack.setImageResource(R.drawable.juxing12);
            tv_title.setText(city);

            ll_isgetorde_top.setVisibility(View.GONE);
            ll_isgetorder_bottom.setVisibility(View.GONE);

            ll_place.setVisibility(View.VISIBLE);
            bottom_layout.setVisibility(View.VISIBLE);
            img_show.setVisibility(View.VISIBLE);
            location_bt.setVisibility(View.VISIBLE);

//            imgBack.setImageResource(R.drawable.juxing12);
//            tv_title.setText(city);

            imgBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onBackPressed();
                }
            });
        }
    }

    @Override
    public void callCarError(String msg) {
        toast(msg);
        ToolsUtil.print("onNext", "叫车出错:" + msg);
    }

    @Override
    public void cancelCallCarSuccess() {
        toast("取消叫车成功");
    }

    @Override
    public void cancelCallCarError(String msg) {
        toast(msg);
    }

    @Override
    public void successInquireInfo(User user1) {
        ToolsUtil.print("----", "查询个人信息成功");

        User user = new UserUtil(this).getUser();
//        user.name = str_tvName;
//        user.sex = str_sex;
//        user.age = str_age;
//        user.zhiye = str_tv_career;
//        user.nickname = str_tvSignature;
//        user.avatar = str_tvSignature;

        user.username = user1.username;
        user.sex = user1.sex;
        user.age = user1.age;
        user.zhiye = user1.zhiye;
        user.nickname = user1.nickname;
        user.avatar = user1.avatar;
        new UserUtil(this).removeUserInfo();
        new UserUtil(this).putUser(user);

        tv_username.setText(user.username);
        tv_phone.setText(user.mobile);
        Glide.with(this)
                .load(user.avatar)
                .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                .centerCrop()
                .into(img_title);
    }

    @Override
    public void errorInquireInfo(String msg) {

    }

    @Override
    public void successBoarding(Dingdan dingdan) {
        rentState = 2;
        toast("已确认上车");
        ll_cancel.setVisibility(View.GONE);
//        ll_isgetorder_bottom.setVisibility(View.GONE);
//        ll_pay_bottom.setVisibility(View.VISIBLE);
        boardingDialog.dismiss();

        tv_driveringContent1.setVisibility(View.GONE);
        tv_driveringContent2.setText("确认已上车，正在行驶中");
//        tv_getInCar.setVisibility(View.GONE);
//        tv_Driving.setVisibility(View.VISIBLE);
        tv_getInCar.setText("行驶中");
        ll_oncar.setEnabled(false);
//        tv_getInCar.setClickable(false);
//        tv_getInCar.setOnClickListener(null);
    }

    @Override
    public void errorBoarding(String msg) {
        toast("确认上车失败: " + msg);
    }

    @Override
    public void successMyStroke(DownWindStroke downWindStroke) {
        tv_downwind_finish_count.setText("共"+downWindStroke.count.finish_count+"个行程");
        tv_downwind_have_count.setText("共"+downWindStroke.count.have_count+"个行程");
        tv_finish_time.setText(downWindStroke.infor.get(0).addtime);
        tv_have_time.setText(downWindStroke.infor.get(1).addtime);
        tv_finish_place.setText(downWindStroke.infor.get(0).departure+"--"+downWindStroke.infor.get(0).destination);
        tv_have_place.setText(downWindStroke.infor.get(1).departure+"--"+downWindStroke.infor.get(1).destination);
    }

    @Override
    public void errorMyStroke() {

    }


    @Override
    public void exception() {
        toast("exception");
    }

    public void initSlidingMenu() {
        // configure the SlidingMenu
        menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        // 设置触摸屏幕的模式
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setShadowWidthRes(R.dimen.shadow_width);
        //      menu.setShadowDrawable(R.color.colorAccent);
        menu.setTouchModeAbove(SlidingMenu.LEFT);//设置要使菜单滑动，触碰屏幕的范围

        // 设置滑动菜单视图的宽度
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        // 设置渐入渐出效果的值
        menu.setFadeDegree(0.35f);
        /**
         * SLIDING_WINDOW will include the Title/ActionBar in the content
         * section of the SlidingMenu, while SLIDING_CONTENT does not.
         */
        menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        //为侧滑菜单设置布局
        menu.setMenu(R.layout.left_menu);

//        menu.showMenu();//显示SlidingMenu
//        menu.showContent();//显示内容

        RelativeLayout rl_title = (RelativeLayout) menu.findViewById(R.id.rl_title);
        rl_title.setOnClickListener(this);
        RelativeLayout rl_setting = (RelativeLayout) menu.findViewById(R.id.rl_setting);
        rl_setting.setOnClickListener(this);
        RelativeLayout rlShare = (RelativeLayout) menu.findViewById(R.id.rlShare);
        rlShare.setOnClickListener(this);
        RelativeLayout rl_Driver = (RelativeLayout) menu.findViewById(R.id.rl_Driver);
        rl_Driver.setOnClickListener(this);
        RelativeLayout rlWallet = (RelativeLayout) menu.findViewById(R.id.rlWallet);
        rlWallet.setOnClickListener(this);
        RelativeLayout rlShop = (RelativeLayout) menu.findViewById(R.id.rlShop);
        rlShop.setOnClickListener(this);
        RelativeLayout rlServer = (RelativeLayout) menu.findViewById(R.id.rlServer);
        rlServer.setOnClickListener(this);
        RelativeLayout rlMessage = (RelativeLayout) menu.findViewById(R.id.rlMessage);
        rlMessage.setOnClickListener(this);

        RelativeLayout rl_menu_stroke = (RelativeLayout) menu.findViewById(R.id.rl_menu_stroke);
        rl_menu_stroke.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //menu.showContent();//显示内容
                startActivity(StrokeActivity.class);
            }
        });
//        imgBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (menu.isMenuShowing())
//                    menu.toggle();
//            }
//        });

        tv_username = (TextView) menu.findViewById(R.id.tv_username);
        tv_phone = (TextView) menu.findViewById(R.id.tv_phone);
        img_title = (CustomImageView) menu.findViewById(R.id.img_title);

        User user = new UserUtil(this).getUser();
        tv_username.setText(user.username);
        tv_phone.setText(user.mobile);
        Glide.with(this)
                .load(user.avatar)
                .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                .centerCrop()
                .into(img_title);

        Map map = new HashMap();
        map.put("user_id", new UserUtil(this).getUserId());
        map.put("type", 1);
        String json = StringUtil.toJson(map);
        try {
            String data1 = AESCrypt.getInstance().encrypt(json);
            String d = StringUtil.replaceBlank(data1);
            presenter.InquireInfo(d);
        } catch (Exception ex) {
        }


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        ActivityUtil.addActivity(this);
        ToolsUtil.exitkey(keyCode, this);//退出
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        menu.toggle();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_title:
                startActivity(OwnInfoActivity.class);
                break;
            case R.id.rl_setting:
                startActivity(SettingActivity.class);
                ActivityUtil.addActivity(this);
                break;
            case R.id.rlShare:
                startActivity(ShareActivity.class);
                break;
            case R.id.rlMessage: // 消息
                startActivity(OwnMsgActivity.class);
                break;
            case R.id.rl_Driver:
                //    startActivity(RegisterCCheckActivity.class);
                startActivity(RegisterCCheckActivity.class, new Bun().putString("lat", Double.toString(lat)).putString("lng", Double.toString(lng)).ok());
                break;
            case R.id.rlWallet:
                startActivity(MyWalletActivity.class);
                break;
            case R.id.rlShop:
                startActivity(IntegralActivity.class);
                break;
            case R.id.rlServer: // 客服
                Map<String,String> map = new HashMap<>();
                map.put("type","1");
                String json = JsonUtils.toJson(map);
                String data1 = null;
                try {
                    data1 = AESCrypt.getInstance().encrypt(json);
                    String d = StringUtil.replaceBlank(data1);
                    OkHttpUtils.post()
                            .url(Const.BASE_URL+"api.php/User/settings")
                            .addParams("args",d)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Call call, Exception e, int i) {

                                }

                                @Override
                                public void onResponse(String response,int i) {
                                    JSONObject json;
                                    try {
                                        json = new JSONObject(response);
                                        int code = json.getInt("code");
                                        if(code == 200){
                                            String data = json.getString("datas");

                                            final TwoButtonDialog dialog = new TwoButtonDialog(getContext());
                                            dialog.setText("拨打客服电话:"+data);
                                            dialog.setConfirmText("拨打");
                                            dialog.txt_queding.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View v) {
                                                    dialog.dismiss();
                                                    Intent it = new Intent();
                                                    it.setAction(Intent.ACTION_CALL);
                                                    it.setData(Uri.parse("tel:"+data));
                                                    startActivity(it);

                                                }
                                            });
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                } catch (Exception e) {
                    e.printStackTrace();
                }

//                Intent it2 = new Intent();
//                it2.putExtra("tag","1");
//                it2.setClass(MainActivity.this, IntroduceEtcActivity.class);
//                startActivity(it2);
                break;
        }
    }

    private Dingdan dingdan;
    // 举报标题
    ArrayList<ReportTitle> listReport = new ArrayList<ReportTitle>();
    IsGetOrderDialog dialogGetOrder;

    public void driverGetOrder(Context context){
        if(spellCar == 1 || spellCar == 5) {
            cancelCallCarDialog.dismiss();
        }else{
            dialogNoWaitting.dismiss();
        }

        Const.downTag = 2;

        dialogGetOrder = new IsGetOrderDialog(getContext());

        dialogGetOrder.tv_name.setText(dingdan.info.driver_realname);
        dialogGetOrder.tvCarnumber.setText(dingdan.info.carnumber);
        dialogGetOrder.tvContent.setText(dingdan.info.carnumber + " " + dingdan.info.driver_realname);
        Glide.with(MainActivity.this)
                .load("http://47.93.113.101/Uploads/" + dingdan.info.avatar)
                .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                .centerCrop()
                .into(dialogGetOrder.img_driver);
        handlerWaitting.removeCallbacks(waittingRunnable);
        dialogGetOrder.txt_queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rentState = 1;
                ll_isgetorde_top.setVisibility(View.VISIBLE);
                ll_isgetorder_bottom.setVisibility(View.VISIBLE);
                tv_driveringContent1.setVisibility(View.VISIBLE);
                tv_driveringContent1.setText("请耐心等待司机");
                tv_driveringContent2.setText("若已上车请点击我已上车");
                tv_getInCar.setText("我已上车");
                tv_driver_name.setText(dingdan.info.driver_realname);
                tv_driver_carnumber.setText(dingdan.info.carnumber);
                tv_startPlace.setText(dingdan.info.departure);
                tv_stopPlace.setText(dingdan.info.destination);
                Glide.with(MainActivity.this)
                        .load("http://47.93.113.101/Uploads/" + dingdan.info.avatar)
                        .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                        .centerCrop()
                        .into(img_driver2);
                ll_call.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setMessage("您确定拨打电话？").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(Intent.ACTION_CALL);
                                Uri data = Uri.parse("tel:" + dingdan.info.driver_mobile);
                                intent.setData(data);
                                startActivity(intent);
                            }
                        }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                            public void onCancel(DialogInterface dialog) {
                                dialog.dismiss();
                            }

                        }).show();
                    }
                });

                ll_place.setVisibility(View.GONE);
                bottom_layout.setVisibility(View.GONE);
                img_show.setVisibility(View.GONE);
                location_bt.setVisibility(View.GONE);

                dialogGetOrder.dismiss();
            }
        });
        dialogGetOrder.ll_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Map map = new HashMap();
                map.put("order_id", dingdan.info.id);
                map.put("user_id", new UserUtil(context).getUserId());
                String json = StringUtil.toJson(map);
                try {
                    String data1 = AESCrypt.getInstance().encrypt(json);
                    String d = StringUtil.replaceBlank(data1);
                    OkHttpUtils.post()
                            .url(Const.BASE_URL + "api.php/Order/passengerCancel_order")
                            .addParams("args", d)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Call call, Exception e, int i) {
                                    Log.e("onError", "取消订单失败");
                                    Toast.makeText(MainActivity.this, "取消订单失败", Toast.LENGTH_SHORT).show();
                                }

                                @Override
                                public void onResponse(String s, int i) {
                                    JSONObject json;
                                    try {
                                        json = new JSONObject(s);
                                        int code = json.getInt("code");
                                        if (code == 200) {
                                            Log.e("onResponse_200", json.getString("message"));
                                            Toast.makeText(context, json.getString("message"), Toast.LENGTH_SHORT).show();
                                            dialogGetOrder.dismiss();
                                        } else {
                                            Log.e("onResponse", json.getString("message"));
                                            Toast.makeText(context, json.getString("message"), Toast.LENGTH_SHORT).show();
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                } catch (Exception ex) {
                }
            }
        });
        dialogGetOrder.llPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setMessage("您确定拨打电话？").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_CALL);
                        Uri data = Uri.parse("tel:" + dingdan.info.driver_mobile);
                        intent.setData(data);
                        startActivity(intent);
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                    }

                }).show();
            }
        });
    }

    /**
     * 行驶中
     */
    public void carRunning(){
        if(spellCar == 1 || spellCar == 5) {
            cancelCallCarDialog.dismiss();
        }else{
            dialogNoWaitting.dismiss();
        }


        Const.downTag = 2;

        ll_isgetorde_top.setVisibility(View.VISIBLE);
        ll_isgetorder_bottom.setVisibility(View.VISIBLE);
        tv_driveringContent1.setVisibility(View.VISIBLE);
        tv_driveringContent2.setVisibility(View.GONE);
        tv_driveringContent1.setText("请等待司机送达");
        tv_getInCar.setText("行驶中");
        tv_driver_name.setText(dingdan.info.driver_realname);
        tv_driver_carnumber.setText(dingdan.info.carnumber);
        tv_startPlace.setText(dingdan.info.departure);
        tv_stopPlace.setText(dingdan.info.destination);
        Glide.with(MainActivity.this)
                .load("http://47.93.113.101/Uploads/" + dingdan.info.avatar)
                .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
                .centerCrop()
                .into(img_driver2);
        ll_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setMessage("您确定拨打电话？").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_CALL);
                        Uri data = Uri.parse("tel:" + dingdan.info.driver_mobile);
                        intent.setData(data);
                        startActivity(intent);
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                    }

                }).show();
            }
        });

        ll_place.setVisibility(View.GONE);
        bottom_layout.setVisibility(View.GONE);
        img_show.setVisibility(View.GONE);
        location_bt.setVisibility(View.GONE);
    }

    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("message")) {
                Bundle bundle = intent.getExtras();
                String r = bundle.getString(JPushInterface.EXTRA_EXTRA);

                JSONObject json;
                try {
                    json = new JSONObject(r);
                    dingdan = new Gson().fromJson(json.toString(), Dingdan.class);
                    JSONObject info = json.getJSONObject("info");
                    String state = info.getString("state");
                    if (state.equals("1")) { // 司机接单

                        driverGetOrder(context);

                    } else if (state.equals("4")) { // 司机取消
                        rentState = 0;
                        Const.downTag = 5;
                        Toast.makeText(getContext(), "司机已取消订单", Toast.LENGTH_SHORT).show();
//                        hujiaocar.setText("呼叫出租车");
//                        sijijiedan_j.setVisibility(View.GONE);
//                        sijijiedan.setVisibility(View.GONE);
//                        txt_XiaoFei.setVisibility(View.VISIBLE);

                        time = 60;

//                        handlerstate.removeCallbacks(runnablestate);
                        if (dialogGetOrder != null) {
                            dialogGetOrder.dismiss();
                        }

                        final OneButtonImgDialog dialog = new OneButtonImgDialog(getContext());

                        dialog.setText("您与司机" + (StringUtil.isEmpty(dingdan.info.carnumber) ? "未绑定车牌号" : "车牌号：" + dingdan.info.carnumber) + "的行程订单已成功取消");
                        dialog.setConfirmText("投诉");
                        dialog.txt_queding.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                final OneButtonReportDialog dialog1 = new OneButtonReportDialog(getContext());
                                dialog1.txt_content.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Map<String, String> map = new HashMap<String, String>();
                                        map.put("type", "2");
                                        String json = JsonUtils.toJson(map);
                                        AESCrypt aesCrypt = null;
                                        try {
                                            aesCrypt = new AESCrypt();
                                            String d = StringUtil.replaceBlank(aesCrypt.encrypt(json));
                                            OkHttpUtils.post()
                                                    .url(Const.BASE_URL + "api.php/Order/dictionaries_title")
                                                    .addParams("args", d)
                                                    .build()
                                                    .execute(new StringCallback() {
                                                        @Override
                                                        public void onError(Call call, Exception e, int i) {

                                                        }

                                                        @Override
                                                        public void onResponse(String response, int i) {
                                                            ToolsUtil.print("----", "获取订单标题返回值：" + response);
                                                            JSONObject json;
                                                            try {
                                                                json = new JSONObject(response);
                                                                int code = json.getInt("code");
                                                                if (code == 200) {
                                                                    JSONArray datas = json.getJSONArray("datas");
                                                                    listReport.clear();
                                                                    listReport = new Gson().fromJson(datas.toString(), new TypeToken<ArrayList<ReportTitle>>() {
                                                                    }.getType());

                                                                    final ListViewDialog dialog2 = new ListViewDialog(getContext());
                                                                    ReportTitleAdapter adapter = new ReportTitleAdapter(getContext(), listReport);
                                                                    dialog2.listview.setAdapter(adapter);

                                                                    dialog2.listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                                                        @Override
                                                                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                                                            dialog1.txt_content.setText(listReport.get(position).getTitle());
                                                                            dialog2.dismiss();
                                                                        }
                                                                    });
                                                                }
                                                            } catch (JSONException e) {
                                                                e.printStackTrace();
                                                            }
                                                        }
                                                    });
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }


                                    }
                                });
                                dialog1.txt_queding.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        String title = dialog1.txt_content.getText().toString();
                                        String content = dialog1.et_content.getText().toString();
                                        Map<String, String> map = new HashMap<String, String>();
                                        map.put("user_id", new UserUtil(getContext()).getUserId());
                                        map.put("complain_id", dingdan.info.driver_user_id);
                                        map.put("title", title);
                                        map.put("content", content);
                                        map.put("order_id", dingdan.info.id);
                                        map.put("type", "1");
                                        String json = JsonUtils.toJson(map);
                                        AESCrypt aesCrypt = null;
                                        try {
                                            aesCrypt = new AESCrypt();
                                            String d = StringUtil.replaceBlank(aesCrypt.encrypt(json));
                                            OkHttpUtils.post()
                                                    .url(Const.BASE_URL + "api.php/Order/complain")
                                                    .addParams("args", d)
                                                    .build()
                                                    .execute(new StringCallback() {
                                                        @Override
                                                        public void onError(Call call, Exception e, int i) {

                                                        }

                                                        @Override
                                                        public void onResponse(String response, int i) {
                                                            JSONObject json;
                                                            try {
                                                                json = new JSONObject(response);
                                                                int code = json.getInt("code");
                                                                if (code == 200) {
                                                                    Toast.makeText(getContext(), "投诉成功", Toast.LENGTH_SHORT).show();
                                                                    clearMapAndDestanition();
                                                                    dialog1.dismiss();
                                                                    dialog.dismiss();
                                                                }
                                                            } catch (JSONException e) {
                                                                e.printStackTrace();
                                                            }
                                                        }
                                                    });
                                        } catch (Exception e) {

                                        }

                                    }
                                });
                            }
                        });

                        bottom_layout.setVisibility(View.VISIBLE);
                        ll_place.setVisibility(View.VISIBLE);
                        ll_isgetorder_bottom.setVisibility(View.GONE);
                        ll_isgetorde_top.setVisibility(View.GONE);
                        ll_pay_bottom.setVisibility(View.GONE);

                        tv_qunaer.setText("你要去哪儿");
                        MainActivity.quna = "";
                        MainActivity.qunalat = "";
                        MainActivity.qunalng = "";

                        aMap.clear();


                        LatLng latLng = new LatLng(MainActivity.lat, MainActivity.lng);
                        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 19));

                        rlTag.setVisibility(View.VISIBLE);


                    } else if (state.equals("5")) { // 待支付
                        Const.downTag = 6;
                        rentState = 3;
                        tv_driveringContent1.setVisibility(View.VISIBLE);
                        ll_pay_bottom.setVisibility(View.VISIBLE);
                        tv_money2.setText(dingdan.info.price);
                        rlSelectPay.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                final SelectPayDialog dialog = new SelectPayDialog(getContext());
                                dialog.llAlipay.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        channel = "alipay";
                                        img_pay_type.setImageResource(R.drawable.alipay);
                                        tv_pay_type.setText("支付宝");
                                        dialog.dismiss();
                                    }
                                });
                                dialog.llWechat.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        channel = "wx";
                                        img_pay_type.setImageResource(R.drawable.wechat);
                                        tv_pay_type.setText("微信");
                                        dialog.dismiss();
                                    }
                                });
                                dialog.llCash.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        channel = "cash";
                                        img_pay_type.setImageResource(R.drawable.cash);
                                        tv_pay_type.setText("现金");
                                        dialog.dismiss();
                                    }
                                });
                            }
                        });
                    } else if (state.equals("8")) { // 司机拒绝现金支付

                    } else if (state.equals("6")) { // 评价
                        Const.downTag = 7;
                        clearMapAndDestanition();
                        StrokeInfor strokeInfor = new Gson().fromJson(info.toString(), StrokeInfor.class);
                        Intent it = new Intent();
                        Bundle bundle1 = new Bundle();
                        bundle1.putSerializable("item", strokeInfor);
                        it.putExtras(bundle1);
                        it.setClass(context, PingJiaSiJiActivity.class);
                        startActivity(it);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                ToolsUtil.print("----", "r:" + r);
            }
        }

    };

    public void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction("message");
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }


    @Override
    public void onLocationGet(PositionEntity entity) {
        Log.i("----", "onLocationGet===" + entity.adname.toString());

        RouteTask.getInstance(getContext()).setStartPoint(entity);
    }

    @Override
    public void onRegecodeGet(PositionEntity entity) {
        ToolsUtil.print("----", "onRegecodeGet===" + entity.adname.toString());
//        if(MainActivity.isshow.equals("yes")) {
        tv_shangche.setText(entity.adname);
        shangchedidian = entity.adname;
        MainActivity.shangche = entity.adname;
//            testSlidingMenu.shangchelat = entity.latitue+"";
//            testSlidingMenu.shangchelng = entity.longitude+"";
        RouteTask.getInstance(getContext()).setStartPoint(entity);
        RouteTask.getInstance(getContext()).search();
//        }
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        Log.i("----", "中心点经纬度" + cameraPosition.toString());
    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        Log.i("----", "中心点经纬度finish" + cameraPosition.toString());
        //标记地图汽车
//        Utils.addEmulateData(aMap,new LatLng(cameraPosition.target.latitude,cameraPosition.target.longitude));
        //逆地理编码
        if (MainActivity.isshow.equals("yes")) {
            MainActivity.shangchelat = cameraPosition.target.latitude + "";
            MainActivity.shangchelng = cameraPosition.target.longitude + "";
            Log.e("shangchelat", shangchelat);
            Log.e("shangchelng", shangchelng);
        }
        mRegeocodeTask.search(Double.parseDouble(MainActivity.shangchelat), Double.parseDouble(MainActivity.shangchelng));//启动逆地理编码服务
//        mRegeocodeTask.search(cameraPosition.target.latitude, cameraPosition.target.longitude);//启动逆地理编码服务
    }

    public static String isshow = "yes";
}
